<template>
	<view class="drawresult" v-if="showDrawInfo">
		<view class="drawresult_top">
			<view class="f-20 f-w">您的奖品</view>
			<view class="f-18 mt-10">{{lotteryinfo.gifts}}</view>
			<image class="prize_img" :src="picUrl+prize_img" mode="aspectFit"></image>
		</view>
		<view class="address_info_box">
			<view class="address_info_title f-w">领取信息</view>
			<view class="address_info">
				<view class="display_flex mt-20">
					<view class="flex-1 f-13 text-l" style="width: 255rpx;">领取时间</view>
					<view class="c-999999 f-12">{{lotteryinfo.receive_time}}</view>
				</view>
				<view class="display_flex mt-20">
					<view class="flex-1 f-13 text-l" style="width: 255rpx;">领取地址</view>
					<view class="c-999999 f-12">{{lotteryinfo.company_name}}</view>
				</view>
				<view class="display_flex mt-20">
					<view class="flex-1 f-13 text-l" style="width: 255rpx;">领取状态</view>
					<rich-text class="" :nodes="lotteryinfo.gifts_receive_text"></rich-text>
				</view>
				<view class="text-c mt-40">
					<image class="ticket_pic" :src="picUrl+lotteryinfo.ticket"
						:style="lotteryinfo.gifts_status==1?'':'opacity: 0.15;'"></image>
				</view>
				<rich-text class="" :nodes="lotteryinfo.tips"></rich-text>
				<view v-if="lotteryinfo.gifts_status==1" class="text-c mt-30" @click="saveQrcode">
					<image class="download_qrcode_pic" :src="onlinePic+'draw/download_qrcode.png'"></image>
					<view class="f-12 c-999999 mt-10">保存到手机</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getHuodongLotteryInfo,
		getCityList,
		getCompanyList
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				lotteryinfo: '',
				prize_img: '',
				showDrawInfo: false,
				haveAddress: true,
				citylist: [],
				city_id: '',
				company_id: '',
				companylist: [],
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			} else {
				if (uni.getStorageSync('onload')) {
					this.getHuodongLotteryInfo()
					uni.removeStorage({
						key: 'onload'
					})
				}
			}
		},
		onLoad: function(options) {
			if (uni.getStorageSync('access_token')) {
				this.getHuodongLotteryInfo()
			}
		},
		methods: {
			getHuodongLotteryInfo() {
				getHuodongLotteryInfo().then(res => {
					if (res.state == 1) {
						this.showDrawInfo = true
						this.lotteryinfo = res.data.info
						var prizelist = res.data.info.prizelist
						var item = prizelist.find(function(item) {
							return res.data.info.gifts_id == item.id
						});
						this.prize_img = item.url
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},

			saveQrcode() {
				var downurl = this.picUrl + this.lotteryinfo.ticket
				uni.downloadFile({
					url: downurl,
					success: function(res) {
						var tempFilePath = res.tempFilePath
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success: function() {
								uni.showToast({
									title: '保存成功了',
									icon: 'none',
									duration: 1500
								});
								console.log('save success');
							},
							fail(e) {
								console.log('下载失败')
							}
						});

					},

				})
			}
		}
	}
</script>

<style lang="scss">
	.drawresult {
		.drawresult_top {
			padding: 60rpx 30rpx 80rpx 30rpx;
			background-color: #FAFAFA;
			text-align: center;
		}

		.prize_img {
			width: 306rpx;
			height: 180rpx;
			margin-top: 40rpx;
		}

		.addressform_box {
			padding: 38rpx 60rpx;

			.addressform_cell {
				margin-top: 40rpx;
				display: flex;
				align-items: center;

				.addressform_lable {
					width: 110rpx;
					font-size: 26rpx;
					text-align: left;
					margin-right: 20rpx;
				}

				.addressform_input_box {
					flex: 1;
					padding: 20rpx 30rpx;
					border-radius: 8rpx;
					border: 1rpx solid #E9E9E9;

					.addressform_input {
						font-size: 26rpx;
					}
				}

				.addressform_textarea_box {
					flex: 1;
					padding: 30rpx 20rpx;
					border-radius: 8rpx;
					border: 1rpx solid #E9E9E9;

					.addressform_textarea {
						width: 100%;
						font-size: 26rpx;
					}
				}
			}
		}

		.address_info_box {
			padding: 38rpx 60rpx;

			.address_info_title {
				font-size: 32rpx;
				padding-left: 12rpx;
				padding-bottom: 15rpx;
				border-bottom: 1rpx solid #E9E9E9;
			}

			.address_info {
				padding: 0 12rpx;
			}

			.step_select {
				.uni-select {
					font-size: 26rpx;
					height: 86rpx !important;
				}
			}
		}

		.ticket_pic {
			width: 240rpx;
			height: 240rpx;
			vertical-align: middle;
		}

		.download_qrcode_pic {
			width: 52rpx;
			height: 52rpx;
			vertical-align: middle;
		}
	}
</style>